#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>

#define NUM_SUPPLY 10
#define INITIAL_HAND_SIZE 5
void testFullDeckCount (void)
{
    struct gameState G;
    int k[NUM_SUPPLY] =
    {
        adventurer, gardens, embargo, village, minion, mine, cutpurse,
        sea_hag, tribute, smithy
    };
    
    initializeGame(2, k, 1, &G);
    
    int deckcount = 10;
    bool fail = false;
    
    int player = G.whoseTurn;
    
    int i;
    for (i = 0; i < deckcount-INITIAL_HAND_SIZE; i++)
    {
        drawCard (player, &G);
        
        int cur_deckcount = fullDeckCount (player, copper, &G) + fullDeckCount (player, estate, &G);
        
        if (cur_deckcount != deckcount)
        {
            printf ("%s: FAIL after drawing %d cards (%d != %d)!\n", __func__, i+1, cur_deckcount, deckcount);
            fail = true;
            break;
        }
    }
    
    if (!fail)
    {
        printf ("%s: PASS after drawing %d cards.\n", __func__, i);
    }
    
    i = 0;
    while (G.handCount[player])
    {
        discardCard(0, player, &G, 0);
        i++;
    }
    endTurn (&G);
    
    int cur_deckcount = fullDeckCount (player, copper, &G) + fullDeckCount (player, estate, &G);
    
    if (cur_deckcount != deckcount)
    {
        printf ("%s: FAIL after discarding %d cards and ending the turn (%d != %d)!\n", __func__, i, cur_deckcount, deckcount);
    }
    else
    {
        printf ("%s: PASS after discarding %d cards and ending the turn.\n", __func__, i);
    }
}

int main (int argc, char *argv[])
{
    testFullDeckCount ();
}
